package com.itheima.home_work.string_split;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;

public class Test {
    public static void main(String[] args) {
        /**
         * 把给定的字符串数据拆分后存储到集合，并遍历集合打印输出数据信息
         * 字符串数据："熊大,20,男,上海,2003-03-10;熊二,19,男,北京,2004-03-10;翠花,20,女,上海,2003-01-10"
         */

        String str = "熊大,20,男,上海,2003-03-10;熊二,19,男,北京,2004-03-10;翠花,20,女,上海,2003-01-10";

        ArrayList<User> users = new ArrayList<>();

        String[] userList = str.split(";");
        for (int i = 0; i < userList.length; i++) {
            String[] user = userList[i].split(",");
            String[] dateInfo = user[4].split("-");
            LocalDate birthday = LocalDate.of(Integer.parseInt(dateInfo[0]), Integer.parseInt(dateInfo[1]), Integer.parseInt(dateInfo[2]));
            users.add(new User(user[0], Integer.parseInt(user[1]), user[2].charAt(0), user[3], birthday, LocalDateTime.now()));

        }

        for (int i = 0; i < users.size(); i++) {
            LocalDate past = LocalDate.of(2000, 1, 1);
            if (users.get(i).getBirthday().isAfter(past)) {
                System.out.println(users.get(i).toString());
            }
        }
    }
}
